#!/bin/bash
#
# Test the Perl image in OpenShift.
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
#

THISDIR=$(dirname ${BASH_SOURCE[0]})
test_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"

source "${THISDIR}/test-lib.sh"
source "${THISDIR}/test-lib-openshift.sh"
source "${THISDIR}/test-lib-perl.sh"

set -eo nounset

trap ct_os_cleanup EXIT SIGINT

test_latest_imagestreams() {
  info "Testing the latest version in imagestreams"
  # Switch to root directory of a container
  pushd "${test_dir}/../.." >/dev/null
  ct_check_latest_imagestreams
  popd >/dev/null
}

ct_os_check_compulsory_vars

ct_os_enable_print_logs

ct_os_cluster_up

# TODO: We should ideally use a local directory instead of ${VERSION}/test/sample-test-app,
# so we can test changes in that example app that are done as part of the PR
ct_os_test_s2i_app ${IMAGE_NAME} "https://github.com/sclorg/s2i-perl-container.git" ${VERSION}/test/sample-test-app "Everything is OK"

ct_os_test_s2i_app ${IMAGE_NAME} "https://github.com/sclorg/dancer-ex.git" . 'Welcome to your Dancer application on OpenShift'

# TODO: this was not working because the referenced example dir was added as part of this commit
ct_os_test_template_app ${IMAGE_NAME} \
                        ${THISDIR}/sample-test-app.json \
                        perl \
                        "Everything is OK" \
                        8080 http 200 "-p SOURCE_REPOSITORY_REF=staging -p VERSION=${VERSION} -p NAME=perl-testing"

# Check the imagestream
test_perl_imagestream

# check if latest imagestream version is correct
test_latest_imagestreams

OS_TESTSUITE_RESULT=0

ct_os_cluster_down

# vim: set tabstop=2:shiftwidth=2:expandtab:

